<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
  
<form:form id="AuthorSaveForm" action="author/save" method="post" modelAttribute="author">
  <c:if test="${not empty message}">
    <div class="${message.type == 'INFO' ? 'ui-state-highlight' : 'ui-state-error'} ui-corner-all" style="padding: 0.5em">
      <c:out value="${message.text}" />
    </div>
  </c:if>
  <!--<form:errors />-->
  <table class="base">
    <tr><td class="align-right">
      <form:label path="fname">
        Imię 
      </form:label>
    </td><td class="align-left">
      <form:input path="fname" cssStyle="width: 200px;"/>
      <form:errors path="fname" cssClass="error-text" />
    </td></tr><tr><td class="align-right">
      <form:label path="lname">
        Nazwisko 
      </form:label>
    </td><td class="align-left">
      <form:input path="lname" cssStyle="width: 200px;" />
      <form:errors path="lname" cssClass="error-text" />
    </td></tr><tr><td class="align-right">
      <form:label path="birthDate">
        Data urodzenia 
      </form:label>
    </td><td class="align-left">
      <form:input id="AuthorBirthDateInput" path="birthDate" cssStyle="width: 200px;" />
      <form:errors path="birthDate" cssClass="error-text" />
      <!--<div id="AuthorBirthDateDtp"></div>-->
    </td></tr>
  </table>
  <button id="AuthorSaveBtn">Dodaj autora</button>
</form:form>
<script type="text/javascript">
$("#AuthorSaveForm").submit(function() {
	$.post($(this).attr("action"), $(this).serialize(), function(html) {
		$("#AuthorSaveForm").replaceWith(html);
		$.get("/book-app/author/list", null, function(html) { 
			$("#AuthorListBox").replaceWith($(html).updateHtml()); 
		}, "html");
	}, "html");
	return false;  
});
$('#AuthorBirthDateInput').datepicker({dateFormat: 'dd-mm-yy', changeYear: true, changeMonth: true, 
										yearRange: '1500:2100', duration: '' });
/*onSelect: function(date) {
	$('#AuthroBirthDateInput').val(date);
}*/
$('#AuthorSaveBtn').button({ icons: {primary: 'ui-icon-circle-plus'} });
</script>
     